"use strict";

var gulp = require("gulp");
var Server = require("webpack-dev-server");
var webpack = require("webpack");
var config = require("../webpack.config.js");

/**
 * Run a dev server from webpack config.
 * Will serve with hot reload for react redux.
 * Will also set a proxy to doc through the task
 * docServer.js
 *
 * @module tasks/webpackDevServer
 */
function webpackDevServer() {
  var plugins = this.opts.plugins;
  config = Object.create(config);
  config.devTool = "eval";
  config.debug = true;

  new Server(webpack(config),
             {
               plublicPath: "/" + config.output.publicPath,
               stats: {
                 color: true
               }
             }).listen(8080, "localhost", function(err) {
                 if (err) {
                   throw new plugins.util.PluginError("webpack-dev-server", err);
                 }
                 plugins.util.log(
                   "[webpack-dev-server]",
                   "http://localhost/webpack-dev-server/index.html");

               });
}
module.exports = webpackDevServer;
